package com.wnhz.work.jy.fragment;


import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.solidfire.gson.Gson;
import com.wnhz.work.jy.MyApplication;
import com.wnhz.work.jy.MyMain;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.activity.AssetsActivity;
import com.wnhz.work.jy.activity.PayPasswordActivity;
import com.wnhz.work.jy.activity.SaleGoldenActivity;
import com.wnhz.work.jy.adapter.AssetsAdapter;
import com.wnhz.work.jy.bean.AssetsBean;
import com.wnhz.work.jy.utils.ConfigUtil;
import com.wnhz.work.jy.utils.DensityUtils;
import com.wnhz.work.jy.utils.xutils3.MyCallBack;
import com.wnhz.work.jy.utils.xutils3.XUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 * ----我的资产
 */
public class MyAssetFragment {
   /* private View view;
    private ListView listView;
    private RelativeLayout include_occupied;

    private AssetsAdapter adapter;
    private List<AssetsBean.MyGoods> list = new ArrayList<>();

    private AssetsActivity assetsActivity;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_my_asset, container, false);
        assetsActivity = (AssetsActivity) getActivity();
        initData();
        initView();
        return view;
    }

    private void initData() {

    }

    private void initView() {
        listView = (ListView) view.findViewById(R.id.listView);
        include_occupied = (RelativeLayout) view.findViewById(R.id.include_occupied);

        WindowManager manager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        int max_height = display.getHeight();
        int fixed_height = DensityUtils.dp2px(getActivity(), 360);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) include_occupied.getLayoutParams();
        params.height = max_height - fixed_height;
        include_occupied.setLayoutParams(params);
        view.findViewById(R.id.tv_addAddress).setOnClickListener(this);


        adapter = new AssetsAdapter(getActivity(), list, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = (int) view.getTag();
                if ("1".equals(list.get(i).getBuy_back())) {
                    if (assetsActivity.assetsBean.getRate() != null && !"".equals(assetsActivity.assetsBean.getRate())) {
                        if ("1".equals(MyApplication.getInstance().userBean.getPayPassword())) {
                            startActivity(new Intent(getActivity(), SaleGoldenActivity.class).putExtra("MyGoods", list.get(i)).putExtra("rate", assetsActivity.assetsBean.getRate()));
                        } else {
                            assetsActivity.showDialogv7(R.string.pay_toast, "取消", "去设置", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    startActivity(new Intent(getActivity(), PayPasswordActivity.class));
                                }
                            });
                        }
                    }
                }

            }
        });

        listView.setAdapter(adapter);
        setBlank();

    }

    private void setBlank() {
        if (list.size() == 0) {
            include_occupied.setVisibility(View.VISIBLE);
        } else {
            include_occupied.setVisibility(View.GONE);
        }
    }

    public void setData(List<AssetsBean.MyGoods> list) {
        this.list.clear();
        this.list.addAll(list);
        adapter.notifyDataSetChanged();
        setBlank();
    }


   *//* private void getData() {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", MyApplication.getInstance().userBean.getUserId());
        //map.put("userId", "158");
        assetsActivity.showDialog();
        XUtil.Post(ConfigUtil.MYASSETS, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
//                Log.d(TAG, "onSuccess() returned: " + result);
                assetsBean = new Gson().fromJson(result, AssetsBean.class);
                list.clear();
                list.addAll(assetsBean.getGoods());
                //tv_money.setText(assetsBean.getAssets());
//                tv_money.setText(MyApplication.getInstance().userBean.getAssets());
//                tv_score.setText(assetsBean.getIntegral());
                adapter.notifyDataSetChanged();
                setBlank();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }

            @Override
            public void onFinished() {
                super.onFinished();
                assetsActivity.closeDialog();
            }
        });
    }*//*

    @Override
    public void onResume() {
        super.onResume();
        //getData();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_addAddress:
                startActivity(new Intent(getActivity(), MyMain.class).putExtra("Pagination", 2));
                break;
        }
    }*/
}
